package com.fantasy9.gameserver.codec;

import org.apache.mina.common.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;

import com.fantasy9.gameserver.message.BaseMessage;
import com.fantasy9.gameserver.message.BaseServerMessage;

public class BaseMessageEncoder extends ProtocolEncoderAdapter {

	@Override
	public void encode(IoSession session, Object message, ProtocolEncoderOutput out)
			throws Exception {
		
		// Since we only write BaseServerMessage, so we can safely cast
		BaseServerMessage baseMsg = (BaseServerMessage)message;
		
		baseMsg.writeToByteBuffer();
		
		out.write(baseMsg.getBuf());
	}

}
